package translate;

import temp.Label;
import tree.BasicExp;
import tree.BasicStm;
import tree.CJUMP;
import tree.CONST;
import tree.ExpList;

public class StringValueCompExp extends Cx {
	frame.Frame frame;
	Exp left, right;
	int type;
	
	public StringValueCompExp(Level lev, Exp l, Exp r, int t) {
		super();
		frame = lev.frame;
		left = l;
		right = r;
		type = t;
	}
	
	BasicStm unCx(Label t, Label f) {
		if (type < 2) {
			BasicExp call = frame.externalCall("strcmp", new ExpList(left.unEx(), new ExpList(right.unEx(), null)));
			
			if (type == 0) //smaller than
				return new CJUMP(CJUMP.LT, call, new CONST(0), t, f);
			if (type == 1) //greater than
				return new CJUMP(CJUMP.GT, call, new CONST(0), t, f);
			if (type == 2) //smaller than or equal
				return new CJUMP(CJUMP.LE, call, new CONST(0), t, f);
			if (type == 3) //greater than or equal
				return new CJUMP(CJUMP.GE, call, new CONST(0), t, f);
		}
		
		return null;
	}
}
